package com.liming.aftersales.controller;

import com.liming.aftersales.service.CustomerReviewService;
import com.liming.common.pojo.dto.aftersales.CustomerReviewPageQuery;
import com.liming.common.pojo.dto.aftersales.ProductReviewPage;
import com.liming.common.pojo.dto.order.user.mini.MiniOrderEvaluateDTO;
import com.liming.common.pojo.vo.PageVO;
import com.liming.common.pojo.vo.aftersales.CustomerReviewVO;
import com.liming.common.pojo.vo.dashboard.CustomerReviewTopCardVO;
import com.liming.common.pojo.vo.review.MiniProductCommentVO;
import com.liming.common.pojo.vo.review.MiniProductReviewVO;
import com.liming.common.result.LMResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liming
 * @date 2025/3/13
 */
@Slf4j
@RestController
@AllArgsConstructor
@Tag(name = "售后服务-Service")
@RequestMapping("/service/after_sales")
public class AfterSalesMircoController {

    private CustomerReviewService customerReviewService;

    @Operation(summary = "客户评论分页查询")
    @GetMapping("customer_review")
    public LMResult<PageVO<CustomerReviewVO>> reviewPage(CustomerReviewPageQuery query) {
        return LMResult.success(customerReviewService.reviewPage(query));
    }

    @Operation(summary = "客户评论顶部卡片")
    @GetMapping("topCard")
    public LMResult<CustomerReviewTopCardVO> topCard() {
        return LMResult.success(customerReviewService.topCard());
    }

    @Operation(summary = "商家评论")
    @PutMapping("customer_review/{id}")
    public LMResult<Boolean> merchantReview(@PathVariable Long id, @RequestParam String content) {
        return LMResult.success(customerReviewService.merchantReview(id, content));
    }

    @Operation(summary = "客户评论删除")
    @DeleteMapping("customer_review/{id}")
    public LMResult<Boolean> reviewDelete(@PathVariable Long id) {
        return LMResult.success(customerReviewService.removeById(id));
    }

    @Operation(summary = "客户评论批量删除")
    @DeleteMapping("customer_review")
    public LMResult<Boolean> reviewDelete(@RequestBody List<Long> ids) {
        return LMResult.success(customerReviewService.removeByIds(ids));
    }

    @Operation(summary = "小程序 - 商品评论列表")
    @GetMapping("customer_review/mini/{id}")
    public LMResult<List<MiniProductCommentVO>> miniProductReviews(@PathVariable Long id) {
        return LMResult.success(customerReviewService.miniProductReviews(id));
    }

    @Operation(summary = "小程序 - 商品评论分页")
    @GetMapping("customer_review/mini/page")
    public LMResult<MiniProductReviewVO> miniPageProductReviews(ProductReviewPage page) {
        return LMResult.success(customerReviewService.miniPageProductReviews(page));
    }

    @Operation(summary = "用户评论的订单数量")
    @GetMapping("user_review_order_count")
    public LMResult<Long> userReviewOrderCount() {
        return LMResult.success(customerReviewService.userReviewOrderCount());
    }

    @Operation(summary = "该订单是否被评价过")
    @GetMapping("can_review/{orderId}")
    public LMResult<Integer> canComment(@PathVariable Long orderId) {
        return LMResult.success(customerReviewService.canComment(orderId));
    }

    @Operation(summary = "小程序 - 用户评价订单")
    @PostMapping("evaluate")
    public LMResult<Boolean> evaluate(@RequestBody MiniOrderEvaluateDTO miniOrderEvaluateDTO) {
        return LMResult.success(customerReviewService.evaluate(miniOrderEvaluateDTO));
    }
}
